<template>

    <!---搜索表单-->
    <div class="search-div">
        <el-form label-width="70px" size="small">
            <el-row>
                <el-col :span="12">
                    <el-form-item label="问卷标题">
                        <el-input v-model="queryDto.biaoti"
                                style="width: 120px"
                                placeholder="问卷标题"
                                ></el-input>
                    </el-form-item>
                </el-col>


                <el-col :span="12">
                <el-form-item label="状态">
                    <el-select
                    class="m-2"
                    placeholder="选择状态"
                    size="small"
                    style="width: 100px"
                    v-model="queryDto.status"
                    >
                    <el-option
                        v-for="item in brandList"
                        :key="item.id"
                        :label="item.statusval"
                        :value="item.id"
                    />
                    </el-select>
                </el-form-item>
                </el-col>
            </el-row>
            <el-row style="display:flex">
                <el-button type="primary" size="small" @click="findGetSurvey">
                    搜索
                </el-button>
                <el-button size="small" @click="resetData">重置</el-button>
            </el-row>
        </el-form>
    </div>


    <!--添加按钮-->
    <!-- <div class="tools-div">
        <el-button type="success" size="small" @click="addMovement">添 加</el-button>
    </div> -->
    <!---数据表格-->
    <el-table :data="list" style="width: 100%">
        <el-table-column type="index" label="序号"/>
        <el-table-column prop="biaoti" label="问卷标题" />
        <el-table-column prop="stype" label="问卷类型" />
        <el-table-column prop="status" label="状态" #default="scope">
            {{
                scope.row.status == 0
                ? '未启用'
                : scope.row.status == 1
                ? '已启用'
                : '已停用'
            }}
        </el-table-column>
        <el-table-column prop="updateTime" label="跟新日期" />
        <el-table-column label="操作" align="center" width="280" #default="scope">


            <el-button type="success" plain @click="finddanbiao(scope.row)" style="padding: 3px; margin-left: 3px;">
                查看
            </el-button>
        <el-button
          v-if=" scope.row.status == 2 && (scope.row.status == 0 || scope.row.status == 2)
          && scope.row.status == 2 "
          type="warning"
          size="small"
          @click="updateStatusSet(scope.row.id, 1)"
          style="padding: 5px; margin-left: 5px;"
        >
          启用
        </el-button>
        <el-button
          v-if="
            scope.row.status == 1 &&
              (scope.row.status == 0 || scope.row.status == 1) && scope.row.status == 1 
          "
          type="warning"
          plain
          size="small"
          @click="updateStatusSet(scope.row.id, 2)"
          style="padding: 5px; margin-left: 5px;"
        >
          停用
        </el-button>
        </el-table-column>
    </el-table>


    <!-- 详情页面 -->
    <el-dialog v-model="dialogVisible" title="详情" width="90%">
        <el-form label-width="120px">
            <el-form-item label="标题名称:">
                <el-text v-model="wen.biaoti"/>{{ wen.biaoti }}
            </el-form-item>
            <el-form-item label="问卷类型:">
                <el-text v-model="wen.stype"/>{{ wen.stype }}
            </el-form-item>
            <el-form-item>
                <!-- <el-form-item label="问卷问题:">
                    <el-text v-model="leftList.condition"/>{{ leftList.condition }}
                </el-form-item>
                <el-form-item label="问卷类型:">
                    <el-text v-model="leftList.optionsId"/>{{ leftList.optionsId == 1 ? '单选' : leftList.optionsId == 2 ? '单选' : '多选' }}
                </el-form-item> -->
                <el-table :data="leftList" style="width: 70%">
                    <el-table-column prop="condition" label="问卷问题" />
                    <!-- <el-table-column prop="optionsId" label="问卷类型" #default="scope">
                    {{
                        scope.row.optionsId == 1
                        ? '单选'
                        : scope.row.optionsId == 2
                        ? '多选'
                        : '单选'
                    }}
                    </el-table-column> -->
                    <el-table-column label="选项">
                         <el-table :data="RightList" style="width: 90%">
                            <el-table-column prop="xuanId" label="选项" />
                            <el-table-column prop="problem" label="选择题目"/>
                            <el-table-column prop="mark" label="分数"/>
                        </el-table>
                    </el-table-column>
                    
                </el-table>

                
            </el-form-item>
            
            <el-form-item>
                <el-button @click="dialogVisible = false">取消</el-button>
            </el-form-item>
        </el-form>
    </el-dialog> 
    <!--分页条-->
    <el-pagination
                    v-model:current-page="pageParams.page"
                    v-model:page-size="pageParams.limit"
                    :page-sizes="[10, 20, 50, 100]"
                    @size-change="findGetSurvey"
                    @current-change="findGetSurvey"
                    layout="total, sizes, prev, pager, next"
                    :total="total"
        />
</template>

<script setup>
import { ref,onMounted } from 'vue'; 
import {findGetSurveyAll,findStatus,updateStatus,findwenTopById} from '@/api/survey';
import { ElMessage,ElMessageBox } from 'element-plus'

//数据模板
let list = ref([])

let leftList = ref([
])
//分页总条数
let total = ref(0)

const brandList = ref([])

const pageParamsForm = {
    page : 1,
    limit: 3
}
const dialogVisible = ref(false)


const wen = ref({
    biaoti:'',
    stype:''
})

let RightList = ref([
])

const pageParams = ref(pageParamsForm)
// 定义搜索表单数据模型
const queryDto = ref({
    surveytitle: "" ,
    office:"",
    status:""
})
onMounted(()=>{
    findGetSurvey()
    findStatusAll()
})
const findGetSurvey = async ()=>{
    const {data} = await findGetSurveyAll(queryDto.value)
    list.value = data
}

const findStatusAll = async ()=>{
    const {data} = await findStatus()
    brandList.value = data
}
//重置
const resetData = () => {
  queryDto.value = { surveytitle: '', office: '',status: '' }
  findGetSurvey()
}
//启动停用
const updateStatusSet = async(id,status)=>{
    await updateStatus(id,status);
    ElMessage.success('操作成功')
    findGetSurvey()
}
//查看详情 根据id查询信息
const finddanbiao =async(row)=>{
    dialogVisible.value = true
    const {data} = await findwenTopById(row.id)
    wen.value = data.wentop
    leftList.value = data.wenleft
    RightList.value = data.map.wenrights
}



</script>

<style lang="scss" scoped>

</style>